package liuch;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

/**
 * 〈一句话功能简述〉<br> 〈功能详细描述〉 -verbose：gc -XX:+PrintGCDetails
 *
 * @author 17101651 on 2018/3/19.
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class DirectMemoryOOM {

    private static final int _1MB = 1024 * 1024;

    public static void main(String[] args) throws IllegalAccessException {
        Field unsafeField = Unsafe.class.getDeclaredFields()[0];
        unsafeField.setAccessible(true);
        Unsafe unsafe = (Unsafe) unsafeField.get(null);
        while (true) {
            unsafe.allocateMemory(_1MB);
        }
    }
}
